package com.panshi.modules.system.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.panshi.modules.system.bean.BeiSysFunction;
import com.panshi.modules.system.bean.BeiSysRole;
import com.panshi.modules.system.mapper.BeiSysFunctionMapper;
import com.panshi.modules.system.service.BeiSysFunctionService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * <p>
 * 功能表  服务实现类
 * </p>
 *
 * @author 小伍
 * @since 2020-08-07
 */
@Service
public class BeiSysFunctionServiceImpl implements BeiSysFunctionService {

    @Autowired
    private BeiSysFunctionMapper beiSysFunctionMapper;
    @Override
    @Cacheable(value = "function", key = "#root.methodName+#rid" )
    public List<BeiSysFunction> queryAll(int rid) {
        return beiSysFunctionMapper.queryAll(rid);
    }

   /* @Override
    public List<BeiSysFunction> queryAllFunction(int fid) {
        return beiSysFunctionMapper.queryAllFunction(fid);
    }*/

   /* @Override
    public List<BeiSysFunction> queryAllbyType(int rid) {
        return beiSysFunctionMapper.queryAllbyType(rid);
    }*/

    @Override
    @Cacheable(value = "function", key = "#root.methodName+#rid+#fid" )
    public List<BeiSysFunction> queryFunction(int fid,int rid) {
        return beiSysFunctionMapper.queryFunction(fid,rid);
    }

    @Override
    @Cacheable(value = "function", key = "#root.methodName+#rid" )
    public List<BeiSysFunction> querybyrid(int rid) {
        return beiSysFunctionMapper.querybyrid(rid);
    }

    @Override
    @Cacheable(value = "function", key = "#root.methodName" )
    public List<BeiSysFunction> queryallpermissions() {
        return beiSysFunctionMapper.queryallpermissions();
    }

    @Override
    @Cacheable(value = "function", key = "#root.methodName+#pid" )
    public List<BeiSysFunction> queryper(@Param("pid") int pid) {
        return beiSysFunctionMapper.queryper(pid);
    }



    @Cacheable(value = "function", key = "#root.methodName+#map" )
    public List<BeiSysFunction> queryBeiSysFunction(Map<String, Integer> map) {
        Page<BeiSysFunction> page = new Page(map.get("currentPage"),map.get("pageSize"));
        QueryWrapper<BeiSysFunction> user=new QueryWrapper<>();
        user.select("fid","url","name","operate","pid","type","create_time","update_time","state");
        user.eq("type",10);
        beiSysFunctionMapper.selectPage(page, user);
        return page.getRecords();
    }

    @Override
    @Cacheable(value = "function", key = "#root.methodName+#fid" )
    public  List<BeiSysFunction> queryFunctionByFid(Integer fid){
        QueryWrapper<BeiSysFunction> user=new QueryWrapper<>();
        user.select("fid","url","name","operate","pid","type","create_time","update_time","state");
        user.eq("pid",fid);
       return beiSysFunctionMapper.selectList(user);
    }
    @Override
    @Cacheable(value = "function", key = "#root.methodName" )
    public Integer queryFunctioncount(){
        return  beiSysFunctionMapper.queryFunctioncount();
    }

    @Override
    @CacheEvict(value="function",allEntries=true)
    public void updateFunctionstate(BeiSysFunction beiSysFunction) {
        beiSysFunctionMapper.updateById(beiSysFunction);
    }

    @Override
    @CacheEvict(value="function",allEntries=true)
    public void addfunction(BeiSysFunction beiSysFunction) {
        beiSysFunctionMapper.insert(beiSysFunction);
    }

    @Override
    @CacheEvict(value="function",allEntries=true)
    public void updateFunction(BeiSysFunction beiSysFunction) {
        beiSysFunctionMapper.updateById(beiSysFunction);
    }

    @Override
    @CacheEvict(value="function",allEntries=true)
    public void deleteFunction(Integer fid) {
        beiSysFunctionMapper.deleteById(fid);
    }

    @Override
    public void deleteFunctionbypid(Integer pid) {
        beiSysFunctionMapper.deleteFunctionbypid(pid);
    }


}
